/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sessionbean;

import entitybean.Media;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Admin
 */
@Stateless
public class MediaSessionBean implements MediaSessionBeanLocal {
    @PersistenceContext(unitName = "DVDShopOnline4-ejbPU")
    private EntityManager em;

    public void persist(Object object) {
        em.persist(object);
    }
/*
 * Phan Van Duong
 * view all media
 */
    public List viewAll() {
        Query q=em.createNamedQuery("Media.findAll");
        return q.getResultList();
    }
/*
 * Phan Van Duong
 * search media like by title
 */
    public List searchMedia(String title) {
        Query q=em.createNamedQuery("Media.findByTitle");
        q.setParameter("title", "%"+title+"%");
        return q.getResultList();
    }
/*
 * Phan Van Duong
 * get media follow id
 */
    public Media getMedias(int mediaId) {
        Media m=em.find(Media.class, mediaId);
        return m;
    }
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
 
}
